package com.theredspace.urbanexpressions.model {
	
	import com.adobe.rtc.authentication.AbstractAuthenticator;
	import com.adobe.rtc.authentication.AdobeHSAuthenticator;
	import com.adobe.rtc.events.SessionEvent;
	import com.adobe.rtc.session.ConnectSession;
	
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;
	
	[Bindable]
	public class LCCSProxy extends Proxy implements IProxy {
	
		public static const NAME:String = "lccsProxy";
			
		private var connectSession:ConnectSession;
		
		private var roomUrl:String = "https://collaboration.adobelivecycle.com/yurivisser/testroom";
		private var userName:String = "yurivssr@yahoo.co.uk";
		private var pass:String = "carla81em";
		
		//-----------------------------------------------------------------
		public function LCCSProxy(data:Object=null) {
			super(NAME, data);
			
			setupConnectSession();
		}
		
		//-----------------------------------------------------------------
		//-----HELPER METHODS
		private function setupConnectSession():void {
			trace("setupConnectSession()");
			
			connectSession = new ConnectSession();
			
			var auth:AdobeHSAuthenticator = new AdobeHSAuthenticator();
			auth.userName = userName;
			auth.password = pass;
			
			connectSession.roomURL = roomUrl;
			connectSession.authenticator = auth;
			connectSession.login();
			
			connectSession.addEventListener(SessionEvent.SYNCHRONIZATION_CHANGE, onSyncChange);
		}
		
		private function onSyncChange(sEct:SessionEvent):void {
			trace("users: " + connectSession.userManager.userCollection.length);
		}
	}
}